// 测试Function构造函数

// new Function( funBody )
let first = new Function( `console.log( Date.now() )` );

console.log( '- '.repeat(20) );
// 通过 Function.prototype.toString 方法获得函数源代码
console.log( first.toString() );
console.log( '- '.repeat(20) );

// 调用函数
first();

// new Function( paramName1, paramName2, ..., funBody )
let second = new Function( 'a', 'b', 'let c = a + b ; return c;' );

console.log( '- '.repeat(20) );
console.log( second.toString() );
console.log( '- '.repeat(20) );

let result = second(10 , 20);
console.log( result );

console.log( '- '.repeat(20) );

// 用"函数声明"定义函数
function third(){
}

let fourth = function(){
}

let fifth = () => {}

let person = {
    name: '阿芳',
    eat(food) {
        console.log(`${this.name}吃${food}`);
    }
}

// 在 JavaScript 中每个函数都是 Function对象(相当于类) 的一个实例
console.log( first.constructor === Function ); // true
console.log( second.constructor === Function ); // true
console.log( third.constructor === Function ); // true
console.log( fourth.constructor === Function ); // true
console.log( fifth.constructor === Function ); // true
console.log( person.eat.constructor === Function ); // true

console.log( Object.constructor === Function );
console.log( Boolean.constructor === Function );
console.log( Symbol.constructor === Function );
console.log( Function.constructor === Function );

// 参考文档
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function